package com.p2p.backend.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.backend.model.BackUser;
import com.p2p.backend.model.Privilege;
import com.p2p.base.dao.BaseMapper;
import com.p2p.base.page.PageVo;

public interface BackUserDao extends BaseMapper{

	@Select("select * from p2p_back_user where login_name=#{loginName} and is_enabled=true")
	BackUser findByLoginName(String loginName);
	
	@Select("select * from p2p_back_user")
	List<Map<String, Object>> listAll();
	
	@Select("select * from p2p_back_user where id = #{id}")
	Map<String, Object> getBackUser(Integer id);
	
	void addBackUser(Map<String, Object> params);

	void updateBackUser(Map<String, Object> params);
	
	@Select("select p.acl,p.name,p.url,p.parent_acl as parentAcl,"
			+ "p.privilege_level, p.sort_no,p.enname from  p2p_user_role ur,"
			+ "p2p_role_privilege rp,p2p_privilege p "
			+ "where ur.role_id = rp.role_id and rp.privilege_acl = p.acl and ur.user_id = #{userId} order by p.privilege_level,p.sort_no,p.acl")
	@Deprecated
	List<Privilege> findPrivilegeByUserId(Long userId);
	
	List<Map<String, Object>> listPage(PageVo vo);
	
	@Insert("insert into p2p_user(uid,umobile,uemail,uname,password,idcard) values(#{uid},#{umobile},#{uemail},#{uname},#{password},#{idcard})")
	void add(Map<String,Object> user);
	
	@Update("update p2p_user set umobile=#{umobile},uemail=#{uemail},uname=#{uname},password=#{password},idcard=#{idcard} where uid=#{uid}")
	void update(Map<String,Object> user);

	@Select("select * from p2p_user where uid = #{uid}")
	Map<String, Object> get(Integer uid);
}
